Imports System.Data.SqlClient
Imports AppsUtility.EncDec

Public Class frmGLTrialBalance
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents dgTrBal As System.Windows.Forms.DataGrid
    Friend WithEvents crBal As System.Windows.Forms.TextBox
    Friend WithEvents drBal As System.Windows.Forms.TextBox
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents gLlistOfTrialBalance1 As GLlistOfTrialBalance
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents cmbYear As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmbMonth As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmdRefresh As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdPrint As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.crBal = New System.Windows.Forms.TextBox()
        Me.drBal = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.dgTrBal = New System.Windows.Forms.DataGrid()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.gLlistOfTrialBalance1 = New GLlistOfTrialBalance()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.cmdRefresh = New DevComponents.DotNetBar.ButtonX()
        Me.cmdPrint = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        Me.cmbYear = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbMonth = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        CType(Me.dgTrBal, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'crBal
        '
        Me.crBal.BackColor = System.Drawing.Color.White
        Me.crBal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.crBal.Location = New System.Drawing.Point(617, 399)
        Me.crBal.Name = "crBal"
        Me.crBal.ReadOnly = True
        Me.crBal.Size = New System.Drawing.Size(116, 26)
        Me.crBal.TabIndex = 110
        Me.crBal.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'drBal
        '
        Me.drBal.BackColor = System.Drawing.Color.White
        Me.drBal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.drBal.Location = New System.Drawing.Point(495, 399)
        Me.drBal.Name = "drBal"
        Me.drBal.ReadOnly = True
        Me.drBal.Size = New System.Drawing.Size(116, 26)
        Me.drBal.TabIndex = 109
        Me.drBal.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(451, 401)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(38, 18)
        Me.Label1.TabIndex = 108
        Me.Label1.Text = "Total"
        '
        'dgTrBal
        '
        Me.dgTrBal.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgTrBal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dgTrBal.CaptionVisible = False
        Me.dgTrBal.DataMember = ""
        Me.dgTrBal.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgTrBal.Location = New System.Drawing.Point(9, 50)
        Me.dgTrBal.Name = "dgTrBal"
        Me.dgTrBal.PreferredColumnWidth = 175
        Me.dgTrBal.ReadOnly = True
        Me.dgTrBal.Size = New System.Drawing.Size(724, 343)
        Me.dgTrBal.TabIndex = 114
        Me.dgTrBal.TabStop = False
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(9, -4)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(49, 18)
        Me.Label2.TabIndex = 108
        Me.Label2.Text = "Month"
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label3.Location = New System.Drawing.Point(180, -4)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(71, 18)
        Me.Label3.TabIndex = 108
        Me.Label3.Text = "Fiscal Year"
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.drBal)
        Me.GroupPanel1.Controls.Add(Me.crBal)
        Me.GroupPanel1.Controls.Add(Me.cmdRefresh)
        Me.GroupPanel1.Controls.Add(Me.cmdPrint)
        Me.GroupPanel1.Controls.Add(Me.cmdExit)
        Me.GroupPanel1.Controls.Add(Me.cmbYear)
        Me.GroupPanel1.Controls.Add(Me.cmbMonth)
        Me.GroupPanel1.Controls.Add(Me.Label3)
        Me.GroupPanel1.Controls.Add(Me.Label1)
        Me.GroupPanel1.Controls.Add(Me.dgTrBal)
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(751, 520)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 284
        Me.GroupPanel1.Text = "GL Trail Balance"
        '
        'cmdRefresh
        '
        Me.cmdRefresh.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdRefresh.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdRefresh.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdRefresh.Location = New System.Drawing.Point(563, 457)
        Me.cmdRefresh.Name = "cmdRefresh"
        Me.cmdRefresh.Size = New System.Drawing.Size(82, 27)
        Me.cmdRefresh.TabIndex = 239
        Me.cmdRefresh.Text = "Refresh"
        '
        'cmdPrint
        '
        Me.cmdPrint.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdPrint.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPrint.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdPrint.Location = New System.Drawing.Point(475, 457)
        Me.cmdPrint.Name = "cmdPrint"
        Me.cmdPrint.Size = New System.Drawing.Size(82, 27)
        Me.cmdPrint.TabIndex = 238
        Me.cmdPrint.Text = "Print"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(651, 457)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 237
        Me.cmdExit.Text = "Exit"
        '
        'cmbYear
        '
        Me.cmbYear.DisplayMember = "Text"
        Me.cmbYear.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbYear.ItemHeight = 19
        Me.cmbYear.Location = New System.Drawing.Point(179, 17)
        Me.cmbYear.Name = "cmbYear"
        Me.cmbYear.Size = New System.Drawing.Size(129, 25)
        Me.cmbYear.TabIndex = 115
        '
        'cmbMonth
        '
        Me.cmbMonth.DisplayMember = "Text"
        Me.cmbMonth.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbMonth.ItemHeight = 19
        Me.cmbMonth.Location = New System.Drawing.Point(9, 17)
        Me.cmbMonth.Name = "cmbMonth"
        Me.cmbMonth.Size = New System.Drawing.Size(158, 25)
        Me.cmbMonth.TabIndex = 115
        '
        'frmGLTrialBalance
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(751, 520)
        Me.ControlBox = False
        Me.Controls.Add(Me.GroupPanel1)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.Location = New System.Drawing.Point(70, 20)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmGLTrialBalance"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        CType(Me.dgTrBal, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim util As New AppsUtility.EncDec
    Public strCon As String = util.toDecrypt(System.Configuration.ConfigurationSettings.AppSettings("SQLString"))
    Dim sqlCon As SqlConnection = New SqlConnection(strCon)
    Dim strsql As String
    Dim sqlCmd As SqlCommand = New SqlCommand(strsql, sqlCon)
    Dim rdr As SqlDataReader

    Private Sub Budgets_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cYr As Integer = Now.Year
        cmbYear.Items.Clear()

        cmbYear.Items.Add((cYr).ToString())
        cmbYear.Items.Add((cYr + 1).ToString())
        'commented jackson on 01 Aug 201 ------------------------------------------------------------------
        'cmbYear.Items.Add((cYr - 2).ToString() + "-" + (cYr - 1).ToString())
        'cmbYear.Items.Add((cYr - 1).ToString() + "-" + (cYr).ToString())
        'cmbYear.Items.Add((cYr).ToString() + "-" + (cYr + 1).ToString())
        ''cmbYear.Items.Add((cYr + 1).ToString() + "-" + (cYr + 2).ToString())
        'If Now.Month <= 5 Then
        '    cmbYear.SelectedItem = (cYr - 1).ToString() + "-" + (cYr).ToString()
        'Else
        '    cmbYear.SelectedItem = (cYr).ToString() + "-" + (cYr + 1).ToString()
        'End If
        'commented jackson on 01 Aug 201 ------------------------------------------------------------------

        cmbMonth.Text = UCase(Now.ToString("MMM"))  '"JAN"
    End Sub
    Private Sub dgTrBal_load()
        Try
            If CompanyID <> 1 Then
                If cmbMonth.SelectedIndex + 1 >= 5 Then
                    strsql = "select acnum,accent,accountname,sum(trxamt) DrAmount," & _
                   "null CrAmount from gltrx a left outer join account b " & _
                    "on a.acnum=b.accountnumber " & _
                    "where (year(trxdate)<'" & cmbYear.Text.Substring(0, 4) & "'  or " & _
                    "(year(trxdate)='" & cmbYear.Text.Substring(0, 4) & "' and month(trxdate)<='" & _
                    cmbMonth.SelectedIndex + 1 & "')) " & _
                  "group by acnum,accent,accountname having sum(trxamt) > 0 " & _
                  "UNION ALL " & _
                   "select acnum,accent,accountname,null  DrAmount," & _
                   "0-sum(trxamt) CrAmount from gltrx a left outer join account b " & _
                    "on a.acnum=b.accountnumber " & _
                    "where (year(trxdate)<'" & cmbYear.Text.Substring(0, 4) & "'  or " & _
                    "(year(trxdate)='" & cmbYear.Text.Substring(0, 4) & "' and month(trxdate)<='" & _
                    cmbMonth.SelectedIndex + 1 & "')) " & _
                  "group by acnum,accent,accountname having sum(trxamt) < 0 " & _
                   " order by acnum,accent "
                Else
                    strsql = "select acnum,accent,accountname,sum(trxamt) DrAmount," & _
                   "null CrAmount from gltrx a left outer join account b " & _
                    "on a.acnum=b.accountnumber " & _
                    "where (year(trxdate)<'" & cmbYear.Text.Substring(5, 4) & "'  or " & _
                    "(year(trxdate)='" & cmbYear.Text.Substring(5, 4) & "' and month(trxdate)<='" & _
                    cmbMonth.SelectedIndex + 1 & "')) " & _
                  "group by acnum,accent,accountname having sum(trxamt) > 0 " & _
                  "UNION ALL " & _
                   "select acnum,accent,accountname,null  DrAmount," & _
                   "0-sum(trxamt) CrAmount from gltrx a left outer join account b " & _
                    "on a.acnum=b.accountnumber " & _
                    "where (year(trxdate)<'" & cmbYear.Text.Substring(5, 4) & "'  or " & _
                    "(year(trxdate)='" & cmbYear.Text.Substring(5, 4) & "' and month(trxdate)<='" & _
                    cmbMonth.SelectedIndex + 1 & "')) " & _
                  "group by acnum,accent,accountname having sum(trxamt) < 0 " & _
                   " order by acnum,accent "
                End If
            Else
                If cmbMonth.SelectedIndex + 1 >= 5 Then
                    strsql = "select acnum,accent,accountname,sum(trxamt) DrAmount," & _
                   "null CrAmount from gltrx a left outer join account b " & _
                    "on a.acnum=b.accountnumber  " & _
                    "where (year(trxdate)<'" & cmbYear.Text.Substring(0, 4) & "'  or " & _
                    "(year(trxdate)='" & cmbYear.Text.Substring(0, 4) & "' and month(trxdate)<='" & _
                    cmbMonth.SelectedIndex + 1 & "')) " & _
                  "group by acnum,accent,accountname having sum(trxamt) > 0 " & _
                  "UNION ALL " & _
                   "select acnum,accent,accountname,null  DrAmount," & _
                   "0-sum(trxamt) CrAmount from gltrx a left outer join account b " & _
                    "on a.acnum=b.accountnumber  " & _
                    "where (year(trxdate)<'" & cmbYear.Text.Substring(0, 4) & "'  or " & _
                    "(year(trxdate)='" & cmbYear.Text.Substring(0, 4) & "' and month(trxdate)<='" & _
                    cmbMonth.SelectedIndex + 1 & "')) " & _
                  "group by acnum,accent,accountname having sum(trxamt) < 0 " & _
                   " order by acnum,accent "
                Else
                    strsql = "select acnum,accent,accountname,sum(trxamt) DrAmount," & _
                   "null CrAmount from gltrx a left outer join account b " & _
                    "on a.acnum=b.accountnumber  " & _
                    "where (year(trxdate)<'" & cmbYear.Text.Substring(5, 4) & "'  or " & _
                    "(year(trxdate)='" & cmbYear.Text.Substring(5, 4) & "' and month(trxdate)<='" & _
                    cmbMonth.SelectedIndex + 1 & "')) " & _
                  "group by acnum,accent,accountname having sum(trxamt) > 0 " & _
                  "UNION ALL " & _
                   "select acnum,accent,accountname,null  DrAmount," & _
                   "0-sum(trxamt) CrAmount from gltrx a left outer join account b " & _
                    "on a.acnum=b.accountnumber  " & _
                    "where (year(trxdate)<'" & cmbYear.Text.Substring(5, 4) & "'  or " & _
                    "(year(trxdate)='" & cmbYear.Text.Substring(5, 4) & "' and month(trxdate)<='" & _
                    cmbMonth.SelectedIndex + 1 & "')) " & _
                  "group by acnum,accent,accountname having sum(trxamt) < 0 " & _
                   " order by acnum,accent "
                End If
            End If
            If sqlCon.State = ConnectionState.Closed Then
                sqlCon.Open()
            End If
            Dim da As New SqlClient.SqlDataAdapter(strsql, sqlCon)
            Dim ds As New DataSet("TRBAL")
            da.Fill(ds, "TRBAL")

            dgTrBal.DataSource = ds
            dgTrBal.DataMember = "TRBAL"
            dgTrBal.ReadOnly = True
            sqlCon.Close()
            dgTrBal.TableStyles.Clear()
            dgTrBal_Style()

            Dim drow As DataRow
            Dim DrTotal, CrTotal As Double
            For Each drow In ds.Tables(0).Rows
                If Not IsDBNull(drow("DrAmount")) Then
                    DrTotal += CDbl(drow("DrAmount"))
                End If
                If Not IsDBNull(drow("CrAmount")) Then
                    CrTotal += CDbl(drow("CrAmount"))
                End If
            Next
            drBal.Text = DrTotal.ToString("0.000")
            crBal.Text = CrTotal.ToString("0.000")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

    Private Sub dgTrBal_Style()
        With dgTrBal
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With

        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Calibri", 9.0!, FontStyle.Bold)
            .MappingName = "TRBAL"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With

        Dim cs As DataGridColumnStyle
        cs = New DataGridTextBoxColumn
        cs.Width = 90
        cs.MappingName = "acnum"
        cs.HeaderText = "A/C No."
        cs.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs)

        Dim cs1 As DataGridColumnStyle
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 90
        cs1.MappingName = "accent"
        cs1.HeaderText = "Dept."
        cs1.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs1)

        Dim cs5 As DataGridColumnStyle
        cs5 = New DataGridTextBoxColumn
        cs5.Width = 270
        cs5.MappingName = "accountname"
        cs5.HeaderText = "Name"
        cs5.NullText = ""
        grdTableStyle.GridColumnStyles.Add(cs5)

        Dim cs0 As DataGridColumnStyle
        cs0 = New DataGridTextBoxColumn
        cs0.Width = 120
        cs0.MappingName = "DrAmount"
        cs0.HeaderText = "Debit Amt ."
        cs0.NullText = ""
        cs0.ReadOnly = True
        cs0.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs0)

        Dim cs4 As DataGridColumnStyle
        cs4 = New DataGridTextBoxColumn
        cs4.Width = 120
        cs4.MappingName = "CrAmount"
        cs4.HeaderText = "Credit Amt ."
        cs4.NullText = ""
        cs4.ReadOnly = True
        cs4.Alignment = HorizontalAlignment.Right
        grdTableStyle.GridColumnStyles.Add(cs4)

        dgTrBal.TableStyles.Add(grdTableStyle)

    End Sub

    Private Sub calDebit()
        Try
            strsql = "select isnull(sum(trxamt),'0') DrAmt from gltrx " & _
            "where year(trxdate)<'" & cmbYear.Text.Substring(5, 4) & "' and " & _
            "(year(trxdate)='" & cmbYear.Text.Substring(5, 4) & "' and month(trxdate)<='" & _
            cmbMonth.SelectedIndex + 1 & "') group by acnum having sum(trxamt) >0"
            sqlCmd.CommandText = strsql
            If sqlCon.State = ConnectionState.Closed Then
                sqlCon.Open()
            End If
            rdr = sqlCmd.ExecuteReader
            Dim TotalDebit As Double = 0
            If rdr.HasRows Then
                While rdr.Read
                    TotalDebit += rdr("DrAmt")
                End While
            End If
            rdr.Close()
            sqlCon.Close()
            drBal.Text = Format(Convert.ToDouble(TotalDebit), "####0.000")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub calCredit()
        Try
            strsql = "select isnull(sum(trxamt),'0') CrAmt from gltrx " & _
            "where year(trxdate)<'" & cmbYear.Text.Substring(5, 4) & "' and " & _
            "(year(trxdate)='" & cmbYear.Text.Substring(5, 4) & "' and month(trxdate)<='" & _
            cmbMonth.SelectedIndex + 1 & "') group by acnum having sum(trxamt) <0"
            sqlCmd.CommandText = strsql
            If sqlCon.State = ConnectionState.Closed Then
                sqlCon.Open()
            End If
            rdr = sqlCmd.ExecuteReader
            Dim TotalCredit As Double = 0
            If rdr.HasRows Then
                While rdr.Read
                    TotalCredit += rdr("CrAmt")
                End While
            End If
            rdr.Close()
            sqlCon.Close()
            crBal.Text = Format(Convert.ToDouble(0 - TotalCredit), "####0.000")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        Me.Cursor = Cursors.WaitCursor
        dgTrBal_load()
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Hide()
    End Sub

    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        Try
            PrintTrBal()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
    Private Sub PrintTrBal()
        Me.Cursor = Cursors.WaitCursor
        Try
            Dim ds As DataSet = New DataSet("JisRpt")
            Dim table As DataTable = New DataTable("JisRpt")
            table.Columns.Add("Str1")
            table.Columns.Add("Str2")
            table.Columns.Add("Dec1")
            table.Columns.Add("Dec2")

            Dim mrow, drow As Integer
            Dim cm As CurrencyManager = BindingContext(dgTrBal.DataSource, dgTrBal.DataMember)
            Dim dv As DataView = cm.List
            dv.RowStateFilter = DataViewRowState.CurrentRows
            mrow = dv.Count
            Dim n As Integer
            For n = 0 To mrow - 1
                Dim nrow As DataRow = table.NewRow()
                If dgTrBal(n, 1).ToString.Trim <> "" Then
                    nrow("Str1") = dgTrBal(n, 0) + "-" + dgTrBal(n, 1)
                Else
                    nrow("Str1") = dgTrBal(n, 0)
                End If
                nrow("Str2") = dgTrBal(n, 2)
                nrow("Dec1") = dgTrBal(n, 3)
                nrow("Dec2") = dgTrBal(n, 4)
                table.Rows.Add(nrow)
            Next

            ds.Tables.Add(table)
            gLlistOfTrialBalance1.Load()
            gLlistOfTrialBalance1.SetDataSource(ds)
            Dim dr, cr As Double
            dr = 0.0
            cr = 0.0

            dr = CDbl(drBal.Text).ToString("#0.000")
            cr = CDbl(crBal.Text).ToString("#0.000")

            gLlistOfTrialBalance1.SetParameterValue("CompanyName", "SAFARI HOUSE GENARAL TRADING COMPANY")
            gLlistOfTrialBalance1.SetParameterValue("ReportName", "TRIAL BALANCE")
            gLlistOfTrialBalance1.SetParameterValue("ReportCriteria", "AS ON END OF:" + cmbMonth.Text + " " + cmbYear.Text)
            gLlistOfTrialBalance1.SetParameterValue("dr", dr)
            gLlistOfTrialBalance1.SetParameterValue("cr", cr)

            If PrntPrv Is Nothing Then
                PrntPrv = New PrintPreviewForm
                PrntPrv.CrRptView.ReportSource = gLlistOfTrialBalance1
                PrntPrv.ShowDialog()
            End If

            'gLlistOfTrialBalance1.PrintToPrinter(1, True, 0, 0)
            gLlistOfTrialBalance1.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        Me.Cursor = Cursors.Default

    End Sub

    Private Sub dgTrBal_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgTrBal.MouseUp
        Dim pt As New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = dgTrBal.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            dgTrBal.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            dgTrBal.Select(hti.Row)
        End If
    End Sub

    Private Sub cmbYear_SelectedIndexChanged(sender As System.Object, e As System.EventArgs)

    End Sub
End Class
